﻿@using DMS.BO.Security.Principal
@model DMS.BO.Models.SearchResult<DMS.Entities.Product>

<table class="table table-hover table-nomargin">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
           <th></th>
        </tr>
    </thead>
    <tbody>

        @foreach (var product in Model.List)
        {
            <tr>
                <td style="width:10%">@product.ID</td>
                <td style="width:70%">@product.Name
                </td>
                <td style="width:10%">
                    @if(PermissionUtility.HasPermission(DMSPermission.SanPham_ChinhSua))
                    {
                        <input type="button" name="@product.ID" id="btnEditProduct" class="btn btn-primary" value="Chỉnh sửa"/>
                    }
                    @if(PermissionUtility.HasPermission(DMSPermission.SanPham_Xoa))
                    {
                        <input type="button" name="@product.ID" id="btnDeleteProduct" class="btn btn-primary" value="Xóa"/>
                    }
                </td>
            </tr>
        }

    </tbody>
</table>

<div id="pager" class="pager">
</div>
@RazorHelpers.RenderPagerScript(Model, "#pager", "#frmProduct")

<script type="text/javascript">
    $("#btnEditProduct").live("click", function () {
        $.get("Product/Edit",{id:this.name}, function (result) {
            $('#dialogContent').html(result);
            openDialog();
        });
    });
    
    $("#btnDeleteProduct").live("click", function () {
        var r = confirm("Bạn chắc chắn muốn xóa sản phẩm này!");
        if (r == true) {
            $.post("Product/Delete", { id: this.name }, function (result) {
                if (result.Code == 0) {
                    $('#frmProduct').submit();
                }
            });
        }
    });
</script>